/*
 * Copyright(C) 2009, kesalin All rights reserved.
 * 
 * File name : ComObjects.h
 * Brief     : 
 * Version   : 1.0
 * Author    : kesalin@gmail.com
 * Date      : 2009-6-5
 */

#pragma once

namespace DragDrop {

/* */

// DataObjectImpl
class DataObjectImpl :
	public ATL::CComObjectRootEx<ATL::CComSingleThreadModel>,
	public IDataObjectImpl {

public:

	BEGIN_COM_MAP(DataObjectImpl)
		COM_INTERFACE_ENTRY(IDataObject)
	END_COM_MAP()

public:

	DataObjectImpl()
	{
	}

	~DataObjectImpl()
	{
	}

	/* */

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

	/* */

	static HRESULT Activate(IDataObject** pp)
	{
		if (pp == 0) {
			return E_INVALIDARG;
		}

		ATL::CComObject<DataObjectImpl>* impl = 0;
		HRESULT hRslt = ATL::CComObject<DataObjectImpl>::CreateInstance(&impl);
		if (FAILED(hRslt)) {
			return hRslt;
		}

		impl->AddRef();

		*pp = impl;

		return S_OK;
	}

	/* */

}; // DataObjectImpl

/* */

// DropSourceImpl
class DropSourceImpl :
	public ATL::CComObjectRootEx<ATL::CComSingleThreadModel>,
	public IDropSourceImpl {

public:

	BEGIN_COM_MAP(DropSourceImpl)
		COM_INTERFACE_ENTRY(IDropSource)
	END_COM_MAP()

public:

	DropSourceImpl()
	{
	}

	~DropSourceImpl()
	{
	}

	/* */

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

	/* */

	static HRESULT Activate(IDropSource** pp, HCURSOR hCursor = 0)
	{
		if (pp == 0) {
			return E_INVALIDARG;
		}

		ATL::CComObject<DropSourceImpl>* impl = 0;
		HRESULT hRslt = ATL::CComObject<DropSourceImpl>::CreateInstance(&impl);
		if (FAILED(hRslt)) {
			return hRslt;
		}

		if (hCursor != 0) {
			impl->SetupCursor(hCursor);
		}

		impl->AddRef();

		*pp = impl;

		return S_OK;
	}

	/* */

}; // DropSourceImpl

/* */

} // namespace DragDrop

